 

package io.cw.config;

import io.cw.dao.*;
import io.cw.utils.RenException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.annotation.Resource;

/**
 * 数据库配置
 *
 * @author  cw
 */
@Configuration
public class DbConfig {
    @Value("${cw.database: mysql}")
    private String database;
    @Resource
    private MySQLGeneratorDao mySQLGeneratorDao;

    @Bean
    @Primary
    public GeneratorDao getGeneratorDao() {
        if ("mysql".equalsIgnoreCase(database)) {
            return mySQLGeneratorDao;
        }
//        else if ("oracle".equalsIgnoreCase(database)) {
//            return oracleGeneratorDao;
//        } else if ("sqlserver".equalsIgnoreCase(database)) {
//            return sqlServerGeneratorDao;
//        } else if ("postgresql".equalsIgnoreCase(database)) {
//            return postgreSQLGeneratorDao;
//        }
        else {
            throw new RenException("不支持当前数据库：" + database);
        }
    }
}
